<?php

namespace App\Http\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Dcat\Admin\Traits\ModelTree;
use Watson\Rememberable\Rememberable;

class Category extends BaseModel
{

    use Rememberable;

    protected $rememberCacheTag = 'henlius_category_cache';

    protected $cache_expire_in_minutes = 1440;

    use ModelTree;
    use HasDateTimeFormatter;
    // use SoftDeletes;

    protected $table = 'category';

    protected $titleColumn = 'title';

    protected $orderColumn = 'sort';

    protected $parentColumn = 'parent_id';

    public $timestamps = true;

    protected $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    public function project()
    {
        return $this->belongsToMany(Project::class);
    }

    protected $fillable = [
        'img',
        'title',
        'parent_id',
        'sort',
    ];
    /**
     *  创建分类
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2022-06-16
     * @param string $title
     * @param int $pid
     * @param integer $sort
     * @param string $img
     * @return void
     */
    public static function categoryCreate($title, $pid, $sort = 0, $img = '')
    {
        $info = self::create(
            [
                'img' => $img,
                'title' => $title,
                'parent_id' => $pid,
                'sort' => $sort
            ]
        );

        return $info->id;
    }
}
